package healthcheck

import (
	"github.com/romberli/das/pkg/message"
	"github.com/romberli/go-util/config"
)

func init() {
	initServiceDebugMessage()
	initServiceInfoMessage()
	initServiceErrorMessage()
}

const (
	// debug
	DebugHealthcheckGetOperationHistoriesByLoginName       = 103101
	DebugHealthcheckGetResultByOperationID                 = 103102
	DebugHealthcheckCheck                                  = 103103
	DebugHealthcheckCheckByHostInfo                        = 103103
	DebugHealthcheckCheckByMySQLServerAndMonitorSystemInfo = 103104
	DebugHealthcheckReviewAccuracy                         = 103105
	DebugHealthcheckSaveResult                             = 103106
	DebugHealthcheckUpdateOperationStatus                  = 103107
	// info
	InfoHealthcheckGetOperationHistoriesByLoginName       = 203101
	InfoHealthcheckGetResultByOperationID                 = 203102
	InfoHealthcheckCheck                                  = 203103
	InfoHealthcheckCheckByHostInfo                        = 203103
	InfoHealthcheckCheckByMySQLServerAndMonitorSystemInfo = 203104
	InfoHealthcheckReviewAccuracy                         = 203105
	InfoHealthcheckSaveResult                             = 203106
	InfoHealthcheckUpdateOperationStatus                  = 203107
	// error
	ErrHealthcheckCheckRange                                          = 403101
	ErrHealthcheckStartTime                                           = 403102
	ErrHealthcheckGetOperationHistoriesByLoginName                    = 403103
	ErrHealthcheckGetResultByOperationID                              = 403104
	ErrHealthcheckCheck                                               = 403105
	ErrHealthcheckCheckByHostInfo                                     = 403106
	ErrHealthcheckCheckByMySQLServerAndMonitorSystemInfo              = 403107
	ErrHealthcheckReviewAccuracy                                      = 403108
	ErrHealthcheckSaveResult                                          = 403109
	ErrHealthcheckUpdateOperationStatus                               = 403110
	ErrHealthcheckCloseConnection                                     = 403111
	ErrHealthcheckCreateApplicationMySQLConnection                    = 403112
	ErrHealthcheckCreateMonitorMySQLConnection                        = 403113
	ErrHealthcheckCreateMonitorClickhouseConnection                   = 403114
	ErrHealthcheckCreateMonitorPrometheusConnection                   = 403115
	ErrHealthcheckCheckByMySQLServerIDGetFromBucket                   = 403116
	ErrHealthcheckCheckByHostInfoGetFromBucket                        = 403117
	ErrHealthcheckCheckByMySQLServerAndMonitorSystemInfoGetFromBucket = 403118
)

func initServiceDebugMessage() {
	message.Messages[DebugHealthcheckGetOperationHistoriesByLoginName] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckGetOperationHistoriesByLoginName,
		"healthcheck:get operation histories by login name completed. message: %s")
	message.Messages[DebugHealthcheckGetResultByOperationID] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckGetResultByOperationID,
		"healthcheck:get result by operation id completed. message: %s")
	message.Messages[DebugHealthcheckCheck] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckCheck,
		"healthcheck:check started. operation id: %d")
	message.Messages[DebugHealthcheckCheckByHostInfo] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckCheckByHostInfo,
		"healthcheck:check by host info started. operation id: %d")
	message.Messages[DebugHealthcheckCheckByMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckCheckByMySQLServerAndMonitorSystemInfo,
		"healthcheck:check by mysql server and monitor system info started. operation id: %d")
	message.Messages[DebugHealthcheckReviewAccuracy] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckReviewAccuracy,
		"healthcheck:review accuracy. message: %s")
	message.Messages[DebugHealthcheckSaveResult] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckSaveResult,
		"healthcheck:save result. message: %s")
	message.Messages[DebugHealthcheckUpdateOperationStatus] = config.NewErrMessage(
		message.DefaultMessageHeader, DebugHealthcheckUpdateOperationStatus,
		"healthcheck:update operation status. message: %s")
}

func initServiceInfoMessage() {
	message.Messages[InfoHealthcheckGetOperationHistoriesByLoginName] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckGetOperationHistoriesByLoginName,
		"healthcheck:get operation histories by login name completed. login name: %s")
	message.Messages[InfoHealthcheckGetResultByOperationID] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckGetResultByOperationID,
		"healthcheck:get result by operation id completed. operation_id: %d, length: %d")
	message.Messages[InfoHealthcheckCheck] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckCheck,
		"healthcheck:check started. operation id: %d")
	message.Messages[InfoHealthcheckCheckByHostInfo] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckCheckByHostInfo,
		"healthcheck:check by host info started. operation id: %d")
	message.Messages[InfoHealthcheckCheckByMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckCheckByMySQLServerAndMonitorSystemInfo,
		"healthcheck:check by mysql server and monitor system info started. operation id: %d")
	message.Messages[InfoHealthcheckReviewAccuracy] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckReviewAccuracy,
		"healthcheck:review accuracy completed. operation id: %d, review: %d")
	message.Messages[InfoHealthcheckSaveResult] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckSaveResult,
		"healthcheck:save result completed. operation id: %d")
	message.Messages[InfoHealthcheckUpdateOperationStatus] = config.NewErrMessage(
		message.DefaultMessageHeader, InfoHealthcheckUpdateOperationStatus,
		"healthcheck:update operation status completed. operation id: %d, status: %d")
}

func initServiceErrorMessage() {
	message.Messages[ErrHealthcheckCheckRange] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCheckRange,
		"check range is larger than the maximum allowed range. check range: %d, allowed range: %d")
	message.Messages[ErrHealthcheckStartTime] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckStartTime,
		"start time is older than the minimum allowed time. start time: %s, minimum allowed time: %s")
	message.Messages[ErrHealthcheckGetOperationHistoriesByLoginName] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckGetOperationHistoriesByLoginName,
		"healthcheck:get operation histories by login name failed. login name: %s")
	message.Messages[ErrHealthcheckGetResultByOperationID] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckGetResultByOperationID,
		"healthcheck:get result by operation id failed. operation id: %d")
	message.Messages[ErrHealthcheckCheck] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCheck,
		"healthcheck:check failed. operation id: %d")
	message.Messages[ErrHealthcheckCheckByHostInfo] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCheckByHostInfo,
		"healthcheck:check by host info failed. operation id: %d")
	message.Messages[ErrHealthcheckCheckByMySQLServerAndMonitorSystemInfo] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCheckByMySQLServerAndMonitorSystemInfo,
		"healthcheck:check by mysql server and monitor system info failed. operation id: %d")
	message.Messages[ErrHealthcheckReviewAccuracy] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckReviewAccuracy,
		"healthcheck:review accuracy failed. operation id: %d")
	message.Messages[ErrHealthcheckSaveResult] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckSaveResult,
		"healthcheck:save result failed. operation id: %d")
	message.Messages[ErrHealthcheckUpdateOperationStatus] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckUpdateOperationStatus,
		"healthcheck:update operation status failed. operation id: %d")
	message.Messages[ErrHealthcheckCloseConnection] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCloseConnection,
		"healthcheck:close middleware connection failed")
	message.Messages[ErrHealthcheckCreateApplicationMySQLConnection] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCreateApplicationMySQLConnection,
		"healthcheck:create application mysql connection failed. addr: %s, user: %s")
	message.Messages[ErrHealthcheckCreateMonitorMySQLConnection] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCreateMonitorMySQLConnection,
		"healthcheck:create monitor mysql connection failed. addr: %s, user: %s")
	message.Messages[ErrHealthcheckCreateMonitorClickhouseConnection] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCreateMonitorClickhouseConnection,
		"healthcheck:create monitor clickhouse connection failed. addr: %s, user: %s")
	message.Messages[ErrHealthcheckCreateMonitorPrometheusConnection] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCreateMonitorPrometheusConnection,
		"healthcheck:create prometheus connection failed. addr: %s, user: %s")
	message.Messages[ErrHealthcheckCheckByMySQLServerIDGetFromBucket] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCheckByMySQLServerIDGetFromBucket,
		"healthcheck: Check(): get from bucket failed. mysql server id: %d, max wait time: %d seconds")
	message.Messages[ErrHealthcheckCheckByHostInfoGetFromBucket] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCheckByHostInfoGetFromBucket,
		"healthcheck CheckByHostInfo(): get from bucket failed. host ip: %s, port number: %d, max wait time: %d seconds")
	message.Messages[ErrHealthcheckCheckByMySQLServerAndMonitorSystemInfoGetFromBucket] = config.NewErrMessage(
		message.DefaultMessageHeader, ErrHealthcheckCheckByMySQLServerAndMonitorSystemInfoGetFromBucket,
		"healthcheck ErrHealthcheckCheckByMySQLServerAndMonitorSystemInfo(): get from bucket failed. operation id: %d, host ip: %s, port number: %d, max wait time: %d seconds")
}
